package 翻转二叉树;

/**
 * @author: zhengtao
 * @description: 翻转二叉树
 * @version: 1.0
 * @date: 2022/10/29  15:50
 */
public class Demo226 {
    public TreeNode invertTree(TreeNode root) {
        if(root==null){
            return root;
        }
        TreeNode left = root.left;
        TreeNode right = root.right;
        root.right=left;
        root.left=right;
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }
    /**
     * Definition for a binary tree node.
     * */
     public class TreeNode {
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode() {}
         TreeNode(int val) { this.val = val; }
         TreeNode(int val, TreeNode left, TreeNode right) {
             this.val = val;
             this.left = left;
             this.right = right;
         }
     }

}
